//
//  ContentViewController.m
//  1227-163MusicDemo
//
//  Created by 千锋 on 15/12/27.
//  Copyright (c) 2015年 千锋. All rights reserved.
//

#import "ContentViewController.h"
#import "LeftViewController.h"
#import "CenterViewController.h"
#import "RightViewController.h"

//屏幕尺寸
#define SCREEN_SIZE [UIScreen mainScreen].bounds.size



@interface ContentViewController ()
{
    LeftViewController * _leftVC;//左侧视图控制器
    CenterViewController * _centerVC ;//中间当前显示的视图控制器
    RightViewController * _rightVC;//右侧视图控制器
}

@end

@implementation ContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //创建子视图控制器
    _leftVC = [[LeftViewController alloc]init];
    _centerVC = [[CenterViewController alloc]init];
    _centerVC.view.backgroundColor = [UIColor orangeColor];
    _rightVC = [[RightViewController alloc]init];
    
    //显示中间的视图控制器的view
    [self.view addSubview:_centerVC.view];
    //设置其他视图控制器的view的位置
    [self makePosition];
    //自定义导航条
    [self cumtomNavi];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//设置子视图的frame 的位置
-(void)makePosition{
    //设置子视图的frame 的位置
    _leftVC.view.frame = CGRectMake(-SCREEN_SIZE.width, 0, SCREEN_SIZE.width, SCREEN_SIZE.height);
    _rightVC.view.frame = CGRectMake(SCREEN_SIZE.width, 0, SCREEN_SIZE.width, SCREEN_SIZE.height);
    //将子视图添加到父视图视图中,因为当前视图控制器的父视图控制器就是在AppDelegate中的申明的导航控制器，
    NSLog(@"self.parentViewController:\t%@",self.parentViewController);
    [self.parentViewController.view addSubview:_leftVC.view];
    [self.parentViewController.view addSubview:_rightVC.view];
    
}

-(void)cumtomNavi{
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(leftItemClicked:)];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightItemClicked:)];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.navigationItem.rightBarButtonItem = rightItem;
}
//@selector
//左侧按钮点击响应事件
-(void)leftItemClicked:(UIBarButtonItem *)sender{
    NSLog(@"left");
    //NSLog(@"self.parentViewController:\t%@",self.parentViewController);
    if (_leftVC.view.frame.origin.x != 0) {
        [UIView animateWithDuration:0.3 animations:^{
            _leftVC.view.frame = self.view.bounds;
        } completion:nil];
    }
}

-(void)rightItemClicked:(UIBarButtonItem *)sender{
    NSLog(@"right");
    if (_rightVC.view.frame.origin.x != 0) {
        [UIView animateWithDuration:0.3 animations:^{
            _rightVC.view.frame = self.view.bounds;
        } completion:nil];
        
    }
}

@end














